package com.fau.wm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 话务客户表
 * @author yangzj
 * @datetime 2014年10月16日,下午3:47:31
 */
@Entity
@Table(name = "medical_call_customer")
public class MedicalCallCustomer implements Serializable, JSONAware {

	private static final long serialVersionUID = -4217848159317676967L;

	private String id; 								// 话务用户表
	private String serialNum; 						// 编号
	private String name; 							// 姓名
	private String sex;								// 性别值
	private Date birthDate; 						// 出生日期
	private Integer age;							// 年龄
	private String customersSource; 				// 客户来源值
	private Date recordingTime; 					// 记录时间
	private String customerServiceId; 				// 客服代表id					
	private String customerLevel;					// 客户级别值
	private String remarks; 						// 备注
	private String provinceId; 						// 省份id
	private String cityId; 							// 城市id
	private String districtId; 						// 区县id
	private String address; 						// 详细地址
	private String zipCode; 						// 邮政编码
	private BigDecimal money; 						// 金额
	private Integer redEnvelopes; 					// 红包
	private Integer integral; 						// 积分
	private String mediaId; 						// 媒体表id
	private String journal;							// 是否邮寄期刊值
	private String recommendId; 					// 推荐人id
	private String hospitalId;						// 医院企业id
	private String userId;							// 我的id
	private String groupId;							// 组id
	private String centerId;						// 中心id
	private String filePath;						// 导入文件上传路径
	private Date createTime = new Date();			// 创建时间
	private Date updateTime = new Date();			// 更新时间
	private String callId;							// 话务任务id
	private String isblack = "0";					// 是否在黑名单中
	
	private MedicalProvince province;				// 省
	private MedicalCity city;						// 城市
	private MedicalDistrict district;				// 地区
	
	private String contactNo;						// 联系电话
	private String keySex;							// 字典表性别
	private String keyCustomersSource;				// 字典表客户来源
	private String keyCustomerLevel;				// 字典表客户级别
	private String keyJournal;						// 字典表是否邮寄
	private Date startTime;							// 开始时间
	private Date endTime;							// 开始时间
	private String keyType; 						// 字典表短信类型
	private String keyPid; 							// 父id
	private String ids;								// 多个id

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "serial_num", length = 20)
	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}

	@Column(name = "name", length = 32)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "sex", length = 32)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "birth_date")
	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	
	@Column(name = "age", length = 5)
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Column(name = "customers_source", length = 32)
	public String getCustomersSource() {
		return customersSource;
	}

	public void setCustomersSource(String customersSource) {
		this.customersSource = customersSource;
	}

	@Column(name = "recording_time", length = 32)
	public Date getRecordingTime() {
		return recordingTime;
	}

	public void setRecordingTime(Date recordingTime) {
		this.recordingTime = recordingTime;
	}

	@Column(name = "customer_service_id", length = 32)
	public String getCustomerServiceId() {
		return customerServiceId;
	}

	public void setCustomerServiceId(String customerServiceId) {
		this.customerServiceId = customerServiceId;
	}
	
	@Column(name = "customer_level", length = 32)
	public String getCustomerLevel() {
		return customerLevel;
	}

	public void setCustomerLevel(String customerLevel) {
		this.customerLevel = customerLevel;
	}

	@Column(name = "remarks", length = 1000)
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	@Transient
	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	@Transient
	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	@Transient
	public String getDistrictId() {
		return districtId;
	}

	public void setDistrictId(String districtId) {
		this.districtId = districtId;
	}

	@Column(name = "address", length = 255)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "zip_code", length = 20)
	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	@Column(name = "money", length = 20)
	public BigDecimal getMoney() {
		return money;
	}

	public void setMoney(BigDecimal money) {
		this.money = money;
	}

	@Column(name = "red_envelopes", length = 11)
	public Integer getRedEnvelopes() {
		return redEnvelopes;
	}

	public void setRedEnvelopes(Integer redEnvelopes) {
		this.redEnvelopes = redEnvelopes;
	}

	@Column(name = "integral", length = 11)
	public Integer getIntegral() {
		return integral;
	}

	public void setIntegral(Integer integral) {
		this.integral = integral;
	}

	@Column(name = "media_id", length = 32)
	public String getMediaId() {
		return mediaId;
	}

	public void setMediaId(String mediaId) {
		this.mediaId = mediaId;
	}
	
	@Column(name = "journal", length = 32)
	public String getJournal() {
		return journal;
	}

	public void setJournal(String journal) {
		this.journal = journal;
	}

	@Column(name = "recommend_id", length = 32)
	public String getRecommendId() {
		return recommendId;
	}

	public void setRecommendId(String recommendId) {
		this.recommendId = recommendId;
	}

	@Column(name = "hospital_id", length = 32)
	public String getHospitalId() {
		return hospitalId;
	}

	public void setHospitalId(String hospitalId) {
		this.hospitalId = hospitalId;
	}

	@Column(name = "user_id", length = 32)
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Column(name = "group_id", length = 32)
	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	@Column(name = "center_id", length = 32)
	public String getCenterId() {
		return centerId;
	}

	public void setCenterId(String centerId) {
		this.centerId = centerId;
	}
	
	@Transient
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@Column(name = "call_id", length = 32)
	public String getCallId() {
		return callId;
	}

	public void setCallId(String callId) {
		this.callId = callId;
	}
	

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "province_id")
	public MedicalProvince getProvince() {
		return province;
	}

	public void setProvince(MedicalProvince province) {
		this.province = province;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "city_id")
	public MedicalCity getCity() {
		return city;
	}

	public void setCity(MedicalCity city) {
		this.city = city;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "district_id")
	public MedicalDistrict getDistrict() {
		return district;
	}

	public void setDistrict(MedicalDistrict district) {
		this.district = district;
	}

	@Transient
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@Transient
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Transient
	public String getKeySex() {
		return keySex;
	}

	public void setKeySex(String keySex) {
		this.keySex = keySex;
	}

	@Transient
	public String getContactNo() {
		return contactNo;
	}

	public void setContactNo(String contactNo) {
		this.contactNo = contactNo;
	}

	@Transient
	public String getKeyCustomersSource() {
		return keyCustomersSource;
	}

	public void setKeyCustomersSource(String keyCustomersSource) {
		this.keyCustomersSource = keyCustomersSource;
	}

	@Transient
	public String getKeyCustomerLevel() {
		return keyCustomerLevel;
	}

	public void setKeyCustomerLevel(String keyCustomerLevel) {
		this.keyCustomerLevel = keyCustomerLevel;
	}

	@Transient
	public String getKeyJournal() {
		return keyJournal;
	}

	public void setKeyJournal(String keyJournal) {
		this.keyJournal = keyJournal;
	}

	@Transient
	public String getKeyType() {
		return keyType;
	}

	public void setKeyType(String keyType) {
		this.keyType = keyType;
	}

	@Transient
	public String getKeyPid() {
		return keyPid;
	}

	public void setKeyPid(String keyPid) {
		this.keyPid = keyPid;
	}

	@Transient
	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	@Column(name = "is_black", length = 5)
	public String getIsblack() {
		return isblack;
	}

	public void setIsblack(String isblack) {
		this.isblack = isblack;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("serialNum", serialNum);
		obj.put("contactNo", contactNo);
		obj.put("name", name);
		obj.put("sex", sex);
		if("8".equals(sex)){
			obj.put("sexName", "男");
		}else if("9".equals(sex)){
			obj.put("sexName", "女");
		}else if("10".equals(sex)){
			obj.put("sexName", "未知");
		}
		obj.put("customersSource", customersSource);
		obj.put("zipCode", zipCode);
		obj.put("keyCustomerLevel", keyCustomerLevel);
		if(null != birthDate) {
			obj.put("birthDate", DateFormatUtils.format(birthDate, "yyyy-MM-dd"));
		}
		obj.put("age", age);
		if(recordingTime != null){
			obj.put("recordingTime", DateFormatUtils.format(recordingTime, "yyyy-MM-dd HH:mm:ss"));
		}
		obj.put("customerServiceId", customerServiceId);
		obj.put("customerLevel", customerLevel);
		obj.put("remarks", remarks);
		if(null != province){
			obj.put("provinceId", province.getId());
			obj.put("pName", province.getpName());
		}
		if(null != city){
			obj.put("cityId", city.getId());
			obj.put("cName", city.getcName());
		}
		if(null != district){
			obj.put("districtId", district.getId());
			obj.put("dName", district.getdName());
		}
		obj.put("address", address);
		obj.put("money", money);
		obj.put("redEnvelopes", redEnvelopes);
		obj.put("integral", integral);
		obj.put("journal", journal);
		obj.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd HH:mm:ss"));
		obj.put("recommendId", recommendId);
		if(StringUtils.isNotBlank(callId)) {
			obj.put("callId", callId);
		}
		if("1".equals(isblack)){
			obj.put("isblackText", "是");
		}else if("0".equals(isblack)){
			obj.put("isblackText", "否");
		}
		return obj.toString();
	}
}
